package com.java.CarDemo;

import java.util.*;

public class CarTest {
    public static void main(String[] args) {
        for (;;){

            Scanner scanner = new Scanner(System.in);
            Bus bus = new Bus(111,"比亚迪","黑色", 200000.0, 1.5f,5);
            FreightCar freightCar = new FreightCar(222,"宝马","白色",500000.0,2.5f,20);
            Lorry lorry = new Lorry(333,"五菱宏光","红色",1000000.0,5.0f,10);

            List<Car> carList = new ArrayList<>();
            carList.add(bus);
            carList.add(freightCar);
            carList.add(lorry);

            //排序
            System.out.println("请选择排序方式：1、按车牌号排序，2、按价格排序，3、按排量排序");
            int op = scanner.nextInt();
            switch (op){
                case 1:
                    //Collections.sort(persons,new IdComparator());
                    Collections.sort(carList, new Comparator<Car>() {
                        @Override
                        public int compare(Car o1, Car o2) {
                            return o1.getCarNumber() - o2.getCarNumber();
                        }
                    });
                    break;
                case 2:
                    Collections.sort(carList, new Comparator<Car>() {
                        @Override
                        public int compare(Car o1, Car o2) {
                            return (int) (o1.getPrice() - o2.getPrice());
                        }
                    });
                    break;
                case 3:
                    Collections.sort(carList, new Comparator<Car>() {
                        @Override
                        public int compare(Car o1, Car o2) {
                            return (int) (o1.getOutput() - o2.getOutput());
                        }
                    });
                    break;
                default:
                    System.out.println("输入错误");
            }
            for (Car car : carList) {
                System.out.println(car);
            }

            //删除
            System.out.println("输入要删除的汽车的车牌号");
            int num = scanner.nextInt();
            for (int i = 0; i < carList.size(); i++) {
                if (carList.get(i).getCarNumber() == num){
                    carList.remove(i);
                }
            }
            for (Car car : carList) {
                System.out.println(car);
            }

            //租车
            System.out.println("请输入要租汽车的车牌号：");
            int num2 = scanner.nextInt();
            for (int i = 0; i < carList.size(); i++) {
                if (carList.get(i).getCarNumber() == num2){
                    System.out.println("该车未出租");
                    carList.get(i).setRented(true);
                    System.out.println("请输入租赁天数");
                    int rentDay = scanner.nextInt();
                    float rPrice = carList.get(i).rentPrice() * rentDay;
                    System.out.println("租金为：" + rPrice);
                    break;
                }else {
                    System.out.println("该车已出租或无此车");
                    break;}
            }

            //还车
            System.out.println("还车");
            System.out.println("还车请输入车牌号");
            int num4 = scanner.nextInt();
            for (Car car : carList) {
                if (car.getCarNumber() == num4) {
                    car.setRented(false);
                    System.out.println("汽车归还成功");
                }
            }
            System.out.println("未找到对应的车牌号");

        }
    }



}
